package com.smh.a01IOStreamDemo1;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class IOStreamDemo7 {
    public static void main(String[] args) throws IOException {

        FileInputStream fis = new FileInputStream("day26-code\\file\\a.txt");
        FileOutputStream fos = new FileOutputStream("day26-code\\file\\b.txt");

        byte[] bytes = new byte[1024 * 1024];
        long start = System.currentTimeMillis();
        //int read = fis.read(bytes);//返回的读的字节数
        //细节: 每次读都会覆盖数组元素,但是如果数据不够,后面的不会被覆盖,那么写入时就会出现错误,写入冗余信息
        //解决:write方法中写入起始和结束索引
        int len;
        while ((len = fis.read(bytes)) > 0) {
            //读多少,写多少
            fos.write(bytes, 0, len);
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        fos.close();
        fis.close();


    }
}
